package Controller.Actions.Add;

import Controller.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import Model.Beans.Results.*;
import Model.Beans.*;
import Model.QBE.*;

public class AddClassroomAction implements Action {

    private String name;
    
    public AddClassroomAction() 
    {
        this.name = "AddClassroom";
    }    

    public String getName()
    {
        return name;
    }
   
    public void perform(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        ClassroomModel cmodel = new ClassroomModel();
        String building = request.getParameter("building");
        String number = request.getParameter("number");
        
        ClassRoom classroom = new ClassRoom(building, Integer.parseInt(number));
        
        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        
        if(cmodel.insert(classroom) != 0)
        {
            response.getWriter().write("<message> The classroom " + classroom.toString() + " has been successfully inserted </message>");
        }
        else
        {
            response.getWriter().write("<message>The ID already exists </message>");
        }
        
    }
}
